﻿<%@ Page Title="AGR: Employees & Trainers" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Employees.aspx.cs" Inherits="AGR.Web.Pages.Employees.Employees" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<%@ Register TagPrefix="uc" TagName="EmployeeForm" Src="~/Controls/Form/EmployeeForm.ascx" %>
<%@ Register TagPrefix="uc" TagName="EmployeeDetail" Src="~/Controls/Form/DetailForm/EmployeeDetail.ascx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="RightContent" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <h3>Employees & Trainers</h3>
    <hr />

    <asp:UpdatePanel ID="EmployeesUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>

        <table>
            <tr>
                <td>Search:</td>
                <td>
                    <asp:TextBox ID="txtSearch" runat="server" CssClass="textbox-small"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="button" 
                        onclick="btnSearch_Click" />
                    <asp:Button ID="btnSearchClear" runat="server" Text="Clear" CssClass="button"
                         OnClick="btnSearchClear_Click" />
                </td>
            </tr>
        </table>

        <br />

        <table>
            <tr>
                <td>
                    <asp:Button ID="btnAdd" runat="server" Text="Add" CssClass="button"
                        onclick="btnAdd_Click" />
                    <asp:Button ID="btnDelete" runat="server" Text="Remove" CssClass="button"
                     OnClick="btnDelete_Click" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="EmployeeGridView" runat="server" CssClass="table-grid" AlternatingRowStyle-CssClass="odd" FooterStyle-CssClass="table-grid-footer"
                    EmptyDataRowStyle-CssClass="empty" EmptyDataText="No subjects found." PagerStyle-CssClass="pager"
                    DataKeyNames="EmployeeCode"
                    AutoGenerateColumns="False" OnRowEditing="EmployeeGridView_RowEditing" onpageindexchanging="EmployeeGridView_PageIndexChanging"
                    OnSelectedIndexChanging="EmployeeGridView_SelectedIndexChanging"
                    AllowPaging="True" PageSize="10">
                        <PagerSettings Mode="NumericFirstLast" Position="Bottom"/>
                        <Columns>
                            <asp:TemplateField HeaderText="Select" HeaderStyle-Width="40px" 
                             HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkSelect" runat="server" CausesValidation="False"> </asp:CheckBox>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:CheckBox ID="chkSelect" runat="server" Enabled="false" CausesValidation="False"> </asp:CheckBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <strong>Add</strong>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Options" HeaderStyle-Width="80px" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkEmployeeDetails" runat="server" CausesValidation="False" Text="Details" CommandName="Select" />
                                    &nbsp;
                                    <asp:LinkButton ID="lnkEmployeeEdit" runat="server" CausesValidation="False" Text="Edit" CommandName="Edit" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:LinkButton ID="lnkEmployeeCancel" runat="server" CausesValidation="False"  CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                    &nbsp;
                                    <asp:LinkButton ID="lnkEmployeeUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"
                                        ValidationGroup="EmployeeUpdateValidationGroup"></asp:LinkButton>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:LinkButton ID="btnEmployeeCancel" runat="server" Text="Cancel" CausesValidation="false" UseSubmitBehavior="false" CommandName="CancelInsert" />
                                    &nbsp;
                                    <asp:LinkButton ID="btnEmployeeInsert" runat="server" Text="Save" UseSubmitBehavior="false" CommandName="Insert"
                                        ValidationGroup="EmployeeSaveValidationGroup" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Code" HeaderStyle-Width="40px">
                                <ItemTemplate><%# Eval("EmployeeCode")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtEmployeeCode" runat="server" Text='<%# Eval("EmployeeCode")%>' Width="30px" Enabled="false"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtEmployeeCode" ID="EmployeeCodeValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtEmployeeCode" runat="server" Width="30px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="EmployeeCodeValidator" runat="server" ErrorMessage=" * " Display="Dynamic" CssClass="ClassValidator"
                                        ControlToValidate="txtEmployeeCode" ValidationGroup="EmployeeSaveValidationGroup"></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="First Name" HeaderStyle-Width="80px">
                                <ItemTemplate><%# Eval("FirstName")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Eval("FirstName")%>' Width="70px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtType" ID="FirstNameValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtFirstName" runat="server" Width="70px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtType" ID="FirstNameValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator"  ValidationGroup="EmployeeSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Last Name" HeaderStyle-Width="80px">
                                <ItemTemplate><%# Eval("LastName")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtLastName" runat="server" Text='<%# Eval("LastName")%>' Width="70px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtLastName" ID="LastNameValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtLastName" runat="server" Width="70px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="LastNameValidator" runat="server" ErrorMessage=" * " Display="Dynamic" CssClass="ClassValidator"
                                        ControlToValidate="txtLastName"  ValidationGroup="EmployeeSaveValidationGroup"></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="ID Number" HeaderStyle-Width="90px">
                                <ItemTemplate><%# Eval("IdNumber")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtIdNumber" runat="server" Text='<%# Eval("IdNumber")%>' Width="80px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtIdNumber" ID="IdNumberValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtIdNumber" runat="server" Width="80px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtIdNumber" ID="IdNumberValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Type" HeaderStyle-Width="130px">
                                <ItemTemplate><%# Eval("Type")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtType" runat="server" Text='<%# Eval("Type")%>' Width="120px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtType" ID="TypeValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtType" runat="server" Width="120px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtType" ID="TypeValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Trainer" HeaderStyle-Width="50px" 
                             HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkTrainer" runat="server" Enabled="false" 
                                        Checked='<%# (Convert.ToInt32(Eval("IsTrainer")) == 1) ? true : false%>' CausesValidation="False"></asp:CheckBox>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:CheckBox ID="chkTrainer" runat="server" Enabled="true"
                                        Checked='<%# (Convert.ToInt32(Eval("IsTrainer")) == 1) ? true : false%>' CausesValidation="False"></asp:CheckBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:CheckBox ID="chkTrainer" runat="server" CausesValidation="False" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Postal Address" HeaderStyle-Width="170px">
                                <ItemTemplate><%# Eval("PostalAddress")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtPostalAddress" runat="server" Text='<%# Eval("PostalAddress")%>' Width="160px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtPostalAddress" ID="PostalAddressValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtPostalAddress" runat="server" Width="160px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtPostalAddress" ID="PostalAddressValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Hire Date" HeaderStyle-Width="130px">
                                <ItemTemplate><%# Eval("HireDate")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtHireDate" runat="server" Text='<%# Eval("HireDate")%>' Width="90px"></asp:TextBox>
                                        <asp:ImageButton ID="ibtnHireDate" runat="server" ImageUrl="~/Content/Images/Buttons/calendar.png" />
                                        <ajaxToolkit:CalendarExtender ID="HireDateCalendarExtender" CssClass="myCalendar" PopupButtonID="ibtnHireDate" Format="dd MMMM yyyy" TargetControlID="txtHireDate" runat="server" />
                                    <asp:RequiredFieldValidator ControlToValidate="txtHireDate" ID="HireDateValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtHireDate" runat="server" Width="90px"></asp:TextBox>
                                        <asp:ImageButton ID="ibtnHireDate" runat="server" ImageUrl="~/Content/Images/Buttons/calendar.png"  />
                                        <ajaxToolkit:CalendarExtender ID="HireDateCalendarExtender" CssClass="myCalendar" PopupButtonID="ibtnHireDate" Format="dd MMMM yyyy" TargetControlID="txtHireDate" runat="server" />
                                    <asp:RequiredFieldValidator ControlToValidate="txtHireDate" ID="HireDateValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="EmployeeSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>


                        </Columns>
                        <PagerStyle HorizontalAlign="Right" Wrap="False" />
                    </asp:GridView>
                </td>
            </tr>
        </table>

        <asp:Panel ID="EmployeeFormPanel" runat="server" style="display: none;">
            <div class="mypopup">
                <div class="header">
                    <asp:Label ID="lblEmployeeForm" runat="server"></asp:Label>
                    <asp:ImageButton ID="btnEmployeeFormClose" CausesValidation="false" CssClass="close" ImageUrl="~/Content/Images/Buttons/close-button.png" runat="server" OnClick="btnEmployeeFormClose_Click" AlternateText="Close" />
                </div>
                <div class="content">
                    <uc:EmployeeForm ID="ucEmployeeForm" runat="server" />
                </div>
            </div>
        </asp:Panel>

        <asp:HiddenField ID="DummyEmployeeFomrTargetControlID" runat="server" />

        <ajaxToolkit:ModalPopupExtender
            BackgroundCssClass="modalpopup" 
            DropShadow="false"
            runat="server"
            TargetControlID="DummyEmployeeFomrTargetControlID"
            PopupControlID="EmployeeFormPanel"
            id="EmployeeFormModalPopupExtender" />

        <asp:Panel ID="EmployeeDetailPanel" runat="server" style="display: none;">
            <div class="mypopup">
                <div class="header">
                    Employee Details
                    <asp:ImageButton ID="btnEmployeeDetailClose" CausesValidation="false" CssClass="close" ImageUrl="~/Content/Images/Buttons/close-button.png" runat="server" OnClick="btnEmployeeDetailsClose_Click" />
                </div>
                <div class="content">
                    <uc:EmployeeDetail ID="ucEmployeeDetail" runat="server" />
                </div>
            </div>
        </asp:Panel>

        <asp:HiddenField ID="DummyEmployeeDetailTargetControlID" runat="server" />

        <ajaxToolkit:ModalPopupExtender
            BackgroundCssClass="modalpopup" 
            DropShadow="false"
            runat="server"
            TargetControlID="DummyEmployeeDetailTargetControlID"
            PopupControlID="EmployeeDetailPanel"
            id="EmployeeDetailModalPopupExtender" />

    </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdateProgress ID="EmployeesUpdateProgress" runat="server" AssociatedUpdatePanelID="EmployeesUpdatePanel">
    <ProgressTemplate>
        <div class="loadingpopup">
            <div class="center">
                <img src="<%=ResolveUrl("~/Content/Images/Shared/spinner.gif") %>" alt="" height="50" width="50" />
            </div>
            <div class="center">
                    Please wait...
            </div>
        </div>
    </ProgressTemplate>
    </asp:UpdateProgress>

</asp:Content>
